<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查询商家</title>
    on ===-->
    <link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon"/>


    <!-- All Vendor & plugins CSS include -->
    <link href="css/vendor.css" rel="stylesheet">
    <!-- Main Style CSS -->
    <link href="css/style.css" rel="stylesheet">

    <!--[if lt IE 9]>
    <script src="/oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="/oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<header class="header-area">
    <!-- main header start -->
    <div class="main-header d-none d-lg-block">
        <!-- header top start -->
        <div class="header-top bdr-bottom">
            <div class="container">
                <div class="row align-items-center">
                    <div class="col-lg-6">
                        <div class="welcome-message">
                            <p>欢迎光临花语在线订花系统</p>
                        </div>
                    </div>
                    <div class="col-lg-6 text-right">
                        <div class="header-top-settings">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- header top end -->

        <!-- header middle area start -->
        <div class="header-main-area sticky">
            <div class="container">
                <div class="row align-items-center position-relative">

                    <!-- start logo area -->
                    <div class="col-lg-3">
                        <div class="logo">
                            <a href="index.html">
                                <h2> HUA YU </h2>
                            </a>
                        </div>
                    </div>
                    <!-- start logo area -->

                    <!-- main menu area start -->
                    <div class="col-lg-6 position-static">
                        <div class="main-menu-area">
                            <div class="main-menu">
                                <!-- main menu navbar start -->
                                <nav class="desktop-menu">
                                    <ul>
                                        <li><a href="index.html">主页</a></li>
                                        <li><a href="store.html">查看商家</a></li>
                                        <li><a href="shopping.html">查看购物车</a></li>
                                    </ul>
                                </nav>
                                <!-- main menu navbar end -->
                            </div>
                        </div>
                    </div>
                    <!-- main menu area end -->

                    <!-- mini cart area start -->
                    <div class="col-lg-3">
                        <div class="header-configure-wrapper">
                            <div class="header-configure-area">
                                <ul class="nav justify-content-end">
                                    <li class="user-hover">
                                        <a href="#" title="个人中心">
                                    <li><img src="{{result.store.simg}}" style="width: 60px" height="60px"></li>
                                    </a>
                                    </li>
                                    <li>
                                        <a href="#">
                                            <h4>退出</h4>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <!-- mini cart area end -->

                </div>
            </div>
        </div>
        <!-- header middle area end -->
    </div>
    <!-- main header start -->
</header>
<!-- end Header Area -->

<!-- main wrapper start -->
<main>
    <!-- breadcrumb area start -->
    <div class="breadcrumb-area common-bg">
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <div class="breadcrumb-wrap">
                        <nav aria-label="breadcrumb">
                            <h1>商家</h1>
                            <br>
                        </nav>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- breadcrumb area end -->
</main>
<div class="container">
    <input id="uname" type="text" placeholder="请输入名字"/>
    <button class="button" id="btnSearch">搜索</button>
    <table class="table">
        <thead>
        <tr>
            <th>商家编号</th>
            <th>商家名称</th>
            <th>商家电话</th>
            <th>商家地址</th>
            <th>商家头像</th>
            <th>注册日期</th>
            <th>商家账号</th>
            <th>商家销量</th>
            <th>商家状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr id="showMsg" style="display: none">
            <td style="text-align: center; font-size: 18px; color: grey"></td>
        </tr>
        </tbody>
    </table>


    <div class="text-right">
        <span id="showPage">共5条数据：当前1/4</span>
        <div class="btn-group" style="display: inline-block">
            <button type="button" class="btn btn-group-sm" id="btnFirst">首页</button>
            <button type="button" class="btn btn-group-sm" id="btnPrev">上一页</button>
            <button type="button" class="btn btn-group-sm" id="btnNext">下一页</button>
            <button type="button" class="btn btn-group-sm" id="btnLast">末页</button>
        </div>
    </div>
</div>


</body>

<script src="js/jquery-3.2.1.js"></script>
<script src="js/global.js"></script>
<script>
    var currentPage = 1;
    var totalPage = 0;

    $(function () {
        query_all_store()
        $('#btnNext').click(function () {
            currentPage++;
            if (currentPage > totalPage) {
                currentPage = totalPage;
            }
            query_all_store()
        })
        $('#btnPrev').click(function () {
            currentPage--;
            if (currentPage <= 0) {
                currentPage = 1;
            }
            query_all_store()
        })
        $('#btnFirst').click(function () {
            currentPage = 1;
            query_all_store()
        })
        $('#btnLast').click(function () {
            currentPage = totalPage;
            query_all_store()
        })

    })


    $('#btnSearch').click(function () {
        var name = $('#uname').val();
        query_all_store(name);
    })


    function query_all_store(name) {
        $('tbody').empty();
        $.getJSON('query_store_all', {sname: name, currpage: currentPage, state: 0}, function (data) {
            totalPage = data.info.pages;
            $('#showPage').text('共' + data.info.total + '条数据，当前' + currentPage + '/' + totalPage + '页')
            $('#showMsg').css('display', 'none');
            $.each(data.data, function (index, obj) {
                var tr1 = '<button type="button" onclick="editStoreInformation(' + obj.sid + ')" class="btn btn-primary">解封</button>&nbsp;&nbsp;&nbsp;&nbsp;'
                var tr = ' <tr>\n' +
                    '            <td>' + obj.sid + '</td>\n' +
                    '            <td>' + obj.sname + '</td>\n' +
                    '            <td>' + obj.phone + '</td>\n' +
                    '            <td>' + obj.saddress + '</td>\n' +
                    '            <td><img width="30px" src='+obj.img+'></img></td>\n' +
                    '            <td>' + obj.hiredate + '</td>\n' +
                    '            <td>' + obj.account + '</td>\n' +
                    '            <td>' + obj.total + '</td>\n' +
                    '            <td>' + (obj.state == 1 ? '可用' : '封禁') + '</td>\n' +
                    '            <td>' + tr1 + '</td>\n';
                $('tbody').append(tr);

            })

        })
    }

    function editStoreInformation(id) {
        $.getJSON('update_store_state', {sid: id, state: 1}, function (data) {
            query_all_store();
        })
        location.href = "query_store.html"
    }


</script>
</html>